import 'dart:async';
import 'dart:convert';
import 'package:flutter_1911/model/home_model.dart';
import 'package:http/http.dart' as http;

const URL = 'https://www.devio.org/io/flutter_app/json/home_page.json';

//首页大接口
class HomeDao {
  static Future<HomeModel> homeRequest() async {
    var url = Uri.parse(URL);
    final response = await http.get(url);
    //等待数据获取成功 成功显示数据
    if (response.statusCode == 200) {
      Utf8Decoder utf8decoder = const Utf8Decoder(); // fix 中文乱码
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      return HomeModel.fromJson(result);
    } else {
      //未获取数据时显示 加载
      throw Exception('加载中...');
    }
  }
}
